<%@page contentType="text/html;charset=UTF-8" language="java"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Date"%>
<%@page import="javax.jdo.PersistenceManager"%>
<%@page import="javax.jdo.Query"%>
<%@page import="de.upb.messerschmidt.set.entity.Event"%>
<%@page import="de.upb.messerschmidt.set.entity.Room"%>
<%@page import="de.upb.messerschmidt.set.entity.Person"%>
<%@page import="de.upb.messerschmidt.set.jdo.PMF"%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Talk Registration</title>
</head>

<body>
	<h1>Talk Registration</h1>
	<p>Please enter the talk information and submit by pressing the
		button</p>
	<form action="talkRoomSelection.jsp" method="post">
		<!-- Locations mit JSP abrufen -->
		<table>
			<tr>
				<td>Event:</td>
				<td><select name="event" size="1">
						<%
							PersistenceManager pm = PMF.get().getPersistenceManager();
							Query query = pm.newQuery(Event.class);
							query.setOrdering("title desc");
							try {
								@SuppressWarnings("unchecked")
								List<Event> events = (List<Event>) query.execute();
								if (!events.isEmpty()) {
									for (Event e : events) {
						%>
						<option>
							<%=e.getTitle()%>: at <%=e.getLocation() %>
						</option>
						<%
							}
								}
							}

							catch (Exception e) {
								e.printStackTrace();
							}
						%>
				</select></td>
			</tr>
			<tr>
				<td>Speaker:</td>
				<td><select name="speaker" size="1">
						<%
							Query personQuery = pm.newQuery(Person.class);
							personQuery.setOrdering("name desc");
							try {
								@SuppressWarnings("unchecked")
								List<Person> persons = (List<Person>) personQuery.execute();
								if (!persons.isEmpty()) {
									for (Person p : persons) {
						%>
						<option>
							<%=p.getName() + ", " + p.getPrename()%>
						</option>
						<%
							}
								}
							}

							catch (Exception e) {
								e.printStackTrace();
							}
						%>
				</select></td>
			</tr>
			<tr>
				<%
					// This snippets creates the current date
					Date date = new Date();
					String day = date.getDate() + "";
					if (Integer.parseInt(day) < 10)
						day = "0" + day;
					String month = date.getMonth() + 1 + "";
					if (Integer.parseInt(month) < 10)
						month = "0" + month;
					String year = (date.getYear() + 1900) + "";
					String valueString = "value = \"" + day + "." + month + "." + year
							+ "\"";
				%>
				<td>Date:</td>
				<td><input type="text" name="date" <%=valueString%> size="10"
					maxlength="10" />
				</td>
			</tr>
			<tr>
				<%
					// This snippets creates the current time
					String h = (date.getHours()+2) + "";
					if (Integer.parseInt(h) < 10)
						h = "0" + h;
					String m = date.getMinutes() + "";
					if (Integer.parseInt(m) < 10)
						m = "0" + m;
					String time = "value = \"" + h + ":" + m + "\"";
				%>
				<td>Time from:</td>
				<td><input type="text" name="timeFrom" <%=time%> size="5"
					maxlength="5" />
				</td>
			</tr>
			<tr>
				<td>Time to:</td>
				<td><input type="text" name="timeTo" <%=time%> size="5"
					maxlength="5" />
				</td>
			</tr>
			<tr>
				<td>Topic:</td>
				<td><input type="text" name="topic" size="50" />
				</td>
			</tr>
			<tr>
				<td>Description:</td>
				<td><textarea name="description" cols=50 rows=6></textarea>
				</td>
			</tr>
			<tr>
				<td><input type="submit" value="Submit" /></td>
				<td><input type="reset" value="Reset"></td>
			</tr>
		</table>
	</form>
</body>
</html>
